package cn.strategy.fund;

import cn.math.MyStatistics;
import org.junit.Test;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class MyStatistics_case1 {
    @Test
    public void my_case() throws ClassNotFoundException, SQLException {
        Class.forName("org.h2.Driver");
        Connection conn = DriverManager.getConnection("jdbc:h2:~/data;AUTO_SERVER=TRUE", "root", "root");

        List<Double> lst = new ArrayList<>();
        String sql = "SELECT PRICE FROM df_stock_date WHERE SYMBOL = '600132' ORDER BY STOCK_DATE DESC LIMIT 0, 7";
        PreparedStatement stmt = conn.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            lst.add(rs.getDouble(1));
        }

        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (conn != null) conn.close();

        Double vs = MyStatistics.my_mean(lst);
        System.out.println(vs);
    }
}

































